package it.carlom.stikkyheader.core;

import ohos.agp.components.Component;
import ohos.agp.components.ListContainer;
import ohos.app.Context;

public class StikkyHeaderListView extends StikkyHeader {

    private final ListContainer mListView;

    StikkyHeaderListView(final Context context, final ListContainer listView, final Component header, final int minHeightHeader, final HeaderAnimator headerAnimator) {
        super(context, header, minHeightHeader, headerAnimator);
        this.mListView = listView;
    }

    @Override
    protected Component getScrollingView() {
        return mListView;
    }

    protected void init() {
        super.init();
        setupOnScrollListener();
    }

    @Override
    protected void setupAnimator() {
        super.setupAnimator();
    }

    @Override
    protected void setHeightHeader(int heightHeader) {
        super.setHeightHeader(heightHeader);
        mListView.setContentOffSet(heightHeader, 0);
    }

    private void setupOnScrollListener() {
        mListView.setScrolledListener((component, scrollX, scrollY, oldScrollX, oldScrollY) -> {
            onScroll(-(scrollY + mHeightHeader));
        });
    }
}
